package com.doubao.device.controller;

import com.doubao.common.result.Result;
import com.doubao.device.dto.DeviceSettingDTO;
import com.doubao.device.dto.request.DeviceSettingRequest;
import com.doubao.device.service.UserDeviceSettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/device/setting")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "智能体设置管理", description = "用户智能体设置相关接口")
public class UserDeviceSettingController {

    private final UserDeviceSettingService settingService;

    @PostMapping
    @Operation(summary = "保存或更新设置", description = "保存或更新用户对智能体的设置")
    public Result<DeviceSettingDTO> saveOrUpdateSetting(
            @Parameter(description = "用户ID") @RequestHeader(value = "X-User-ID", required = false) Long userId,
            @Validated @RequestBody DeviceSettingRequest request) {
        return settingService.saveOrUpdateSetting(userId, request);
    }

    @GetMapping("/{deviceId}")
    @Operation(summary = "获取用户设置", description = "获取用户对指定智能体的设置")
    public Result<DeviceSettingDTO> getUserDeviceSetting(
            @Parameter(description = "用户ID") @RequestHeader(value = "X-User-ID", required = false) Long userId,
            @Parameter(description = "智能体ID") @PathVariable Long deviceId) {
        return settingService.getUserDeviceSetting(userId, deviceId);
    }

    @DeleteMapping("/{deviceId}")
    @Operation(summary = "删除设置", description = "删除用户对指定智能体的设置")
    public Result<Void> deleteSetting(
            @Parameter(description = "用户ID") @RequestHeader(value = "X-User-ID", required = false) Long userId,
            @Parameter(description = "智能体ID") @PathVariable Long deviceId) {
        return settingService.deleteSetting(userId, deviceId);
    }

    @GetMapping("/default/{deviceId}")
    @Operation(summary = "获取默认设置", description = "获取指定智能体的默认设置")
    public Result<DeviceSettingDTO> getDefaultSetting(
            @Parameter(description = "智能体ID") @PathVariable Long deviceId) {
        return settingService.getDefaultSetting(deviceId);
    }
} 